var postsData = require('data/post-data.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrls: [
      'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
      'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
      'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg'
    ],
    indicatorDots: true,
    autoplay: true,
    interval: 5000,
    duration: 1000,
    indicatorColor: "rgba(0, 0, 0, .5)",
    indicatorActiveColor: "#fff",

  },
  showDetail(e) {
    var id = e.currentTarget.dataset.postId;
    var views = wx.getStorageSync('view');
    views[id] = views[id] + 1;;
    wx.setStorageSync('view', views);
    wx.navigateTo({
      url: 'post-detail/post-detail?id=' + id,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    // console.log('onReady');
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // console.log('onShow');
    // 本地存储每个详情页被点击的次数
    if (wx.getStorageSync('view')) {
      var views = wx.getStorageSync('view');
      for (var i = 0; i < postsData.postList.length; i++) {
        postsData.postList[i].view = views[i];
      }
    } else {
      var data = {};
      for (var i = 0; i < postsData.postList.length; i++) {
        data[i] = postsData.postList[i].view;
      }
      console.log(data);
      wx.setStorageSync('view', data);
    }
    this.setData({
      listContentData: postsData.postList
    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    // console.log('onHide');
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    // console.log('onUnload');
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    // console.log('onPullDownRefresh');
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    // console.log('onReachBottom');
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    // console.log('onShareAppMessage');
  }
})